import React, { useState, useEffect } from 'react';

import { NavBar, Icon, Grid } from 'antd-mobile';

import { createForm } from 'rc-form'

import './customerService.scss';

import { GetTutorCallCenterOfTutor, GetParentCallCenterOfTutor } from "@/api/login.js"; // login api

function CustomerService (props) {
    let [knowHtml, setKnowHtml] = useState("");

    // 家教 客服中心
    function axiosGetTutorCallCenterOfTutor () {
        GetTutorCallCenterOfTutor().then(res => {
            if (res.code == "000000") {
                setKnowHtml(res.responseData)
            }
        })
            .catch((err) => {
                console.log('err ----->>>', err)
            })
    }

    // 家长 客服中心
    function axiosGetParentCallCenterOfTutor () {
        GetParentCallCenterOfTutor().then(res => {
            if (res.code == "000000") {
                setKnowHtml(res.responseData)
            }
        })
            .catch((err) => {
                console.log('err ----->>>', err)
            })
    }

    useEffect(() => {
        // 用户角色判断
        if (sessionStorage.getItem('roleVal') == 'TUTOR') {
            axiosGetTutorCallCenterOfTutor()
        } else {
            axiosGetParentCallCenterOfTutor()
        }
    }, [])


    return (
        <div className="customer-service">
            <div className="page-title customer-service-tit">
                <NavBar
                    mode="light"
                    icon={<Icon type="left" />}
                    onLeftClick={() => {
                        if (sessionStorage.getItem('roleVal') == 'TUTOR') {
                            props.history.push({
                                pathname: '/mainTutor',
                                query: {
                                    selectedTab: 'my'
                                }
                            })
                        } else {
                            props.history.push({
                                pathname: '/main',
                                query: {
                                    selectedTab: 'my'
                                }
                            })
                        }

                    }}
                >
                    客服中心
                </NavBar>
            </div>
            <div className="page-content customer-service-con" dangerouslySetInnerHTML={{ __html: knowHtml }}>

            </div>
        </div>
    );
}

CustomerService = createForm()(CustomerService);

export default CustomerService;